package cn.lyq.card.utils

import android.app.Dialog
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import cn.lyq.card.R


class LoadingDialog(context: Context, myDialogStyle: Int) : Dialog(context, myDialogStyle) {


    class Builder(context: Context) {
        private val context: Context
        private var isCancelable = false
        private var isCancelOutside = false

        /**
         * 设置是否可以按返回键取消
         * @param isCancelable
         * @return
         */
        fun setCancelable(isCancelable: Boolean): Builder {
            this.isCancelable = isCancelable
            return this
        }

        /**
         * 设置是否可以取消
         * @param isCancelOutside
         * @return
         */
        fun setCancelOutside(isCancelOutside: Boolean): Builder {
            this.isCancelOutside = isCancelOutside
            return this
        }

        fun create(): LoadingDialog {
            val inflater = LayoutInflater.from(context)
            val view: View = inflater.inflate(R.layout.dialog_loading, null)
            val loadingDialog = LoadingDialog(context, R.style.MyDialogStyle)
            loadingDialog.setContentView(view)
            loadingDialog.setCancelable(isCancelable)
            loadingDialog.setCanceledOnTouchOutside(isCancelOutside)
            return loadingDialog
        }

        init {
            this.context = context
        }
    }
}